#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "unistd.h"
#include "stdio.h"
#include "stdlib.h"

//gcc open.c -o open
//chmod 777 open

#define RWRWRW (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)

int main(void)
{
	int fd1,fd2;
	int ret;

	fd1 = open("./write.txt", O_RDWR | O_CREAT, RWRWRW);
	if(-1 == fd1)
	{
		perror("fd1 open failed");
		return fd1;
	}
	fd2 = open("./read.txt", O_RDONLY);
	if(-1 == fd2)
	{
		perror("fd2 open failed");
		return fd2;
	}

	char buff[1024];

	ret = read(fd2, buff, sizeof(buff));
	if(-1 == ret)
	{
		printf("read fd2 failed");
		return ret;
	}
	ret = write(fd1, buff, sizeof(buff));
	if(-1 == ret)
	{
		printf("write fd1 failed");
		return ret;
	}

	close(fd1);
	close(fd2);


}
